﻿using Sgr.Domain.Entities;
using Sgr.Domain.Managers;
using Sgr.Identity.Services;

namespace Sgr.UPMS.Domain.Users
{
    public interface IUserManage : IDomainManager
    {
        /// <summary>
        /// 创建一个新的用户 [常规模式]
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="passwordHashService"></param>
        /// <param name="passWord"></param>
        /// <param name="isAdmin"></param>
        /// <param name="orgId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<User> CreateNewAsync(string loginName, IPasswordHashService passwordHashService, string passWord, bool isAdmin, long orgId, CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证登录名的唯一性
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <param name="excludeId">需要排除检查的用户ID（可选）</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>领域规则检查结果</returns>
        Task<DomainRuleCheckResult> ValidateLoginNameUniquenessAsync(string loginName,
            long? excludeId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证手机号码的唯一性
        /// </summary>
        /// <param name="phoneNumber">手机号码</param>
        /// <param name="excludeId">需要排除检查的用户ID（可选）</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>领域规则检查结果</returns>
        Task<DomainRuleCheckResult> ValidatePhoneNumberUniquenessAsync(string phoneNumber,
            long? excludeId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证电子邮箱的唯一性
        /// </summary>
        /// <param name="email">电子邮箱地址</param>
        /// <param name="excludeId">需要排除检查的用户ID（可选）</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>领域规则检查结果</returns>
        Task<DomainRuleCheckResult> ValidateEmailUniquenessAsync(string email,
            long? excludeId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证微信OpenId的唯一性
        /// </summary>
        /// <param name="weChatOpenId">微信OpenId</param>
        /// <param name="excludeId">需要排除检查的用户ID（可选）</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>领域规则检查结果</returns>
        Task<DomainRuleCheckResult> ValidateWeChatOpenIdUniquenessAsync(string weChatOpenId,
            long? excludeId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证微信UnionId的唯一性
        /// </summary>
        /// <param name="weChatUnionId">微信UnionId</param>
        /// <param name="excludeId">需要排除检查的用户ID（可选）</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>领域规则检查结果</returns>
        Task<DomainRuleCheckResult> ValidateWeChatUnionIdUniquenessAsync(string weChatUnionId,
            long? excludeId = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 检查角色是否被用户使用
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> HasUserUseRoleAsync(long roleId, CancellationToken cancellationToken = default);

        /// <summary>
        /// 检查用户是否可以删除
        /// </summary>
        /// <param name="user"></param>
        /// <param name="operatorUser"></param>
        /// <returns></returns>
        DomainRuleCheckResult CheckBeforeDeletion(User user, User operatorUser);

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="userId">待删除的用户标识</param>
        /// <param name="operatorUserId">操作者的用户标识</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>是否删除成功</returns>
        Task<bool> DeleteUserAsync(long userId, long operatorUserId, CancellationToken cancellationToken = default);
    }
}